package com.wuxi.zhang.base.exception;

import com.wuxi.zhang.base.result.Result;
import com.wuxi.zhang.base.result.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 *
 * @author zhang on 2018/10/18.
 */
@ControllerAdvice
@Slf4j
@Order(2)
public class ExceptionHandle {

    /**
     * @return
     * @ExceptionHandler(value = Exception.class):声明要捕获的异常类
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handle(Exception e) {
        log.error("【系统异常】 {}", e);
        return ResultUtil.error(500, "系统错误");
    }
}
